/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.view;

import com.minierp.bean.EstablishmentCommunicateBean;
import com.minierp.model.EstablishmentCommunicate;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.Region;
import org.springframework.web.servlet.view.document.AbstractExcelView;

public class EstablishmentCommunicateCalendarExcelView
		extends
			AbstractExcelView {
	protected void buildExcelDocument(Map model, HSSFWorkbook workbook,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		response.reset();
		response.setContentType("APPLICATION/vnd.ms-excel");
		response.setHeader("Content-Disposition",
				"attachment;filename=\"EstablishmentCommunicateCalendar.xls\"");
		HSSFFont titltFont = workbook.createFont();
		titltFont.setFontHeightInPoints(16);
		titltFont.setBoldweight(700);
		HSSFFont boldFont = workbook.createFont();
		boldFont.setBoldweight(700);
		HSSFCellStyle titleCellStyle = workbook.createCellStyle();
		titleCellStyle.setFont(titltFont);
		titleCellStyle.setAlignment(2);
		titleCellStyle.setVerticalAlignment(1);
		HSSFCellStyle boldStyle = workbook.createCellStyle();
		boldStyle.setFont(boldFont);
		boldStyle.setBorderBottom(1);
		boldStyle.setBorderTop(1);
		boldStyle.setBorderLeft(1);
		boldStyle.setBorderRight(1);
		boldStyle.setAlignment(2);
		HSSFCellStyle norStyle = workbook.createCellStyle();
		norStyle.setBorderBottom(1);
		norStyle.setBorderTop(1);
		norStyle.setBorderLeft(1);
		norStyle.setBorderRight(1);
		HSSFSheet sheet = workbook.createSheet("list");
		byte index = 0;
		HSSFRow r = sheet.createRow(index);
		HSSFCell c = r.createCell(0);
		byte colNum = 7;

		for (int list = 1; list < colNum; ++list) {
			r.createCell((short) list);
		}

		c.setCellStyle(titleCellStyle);
		c.setCellValue(new HSSFRichTextString((String) model.get("stafName")
				+ " 工作日志"));
		sheet.addMergedRegion(new Region(index, 0, index, (short) (colNum - 1)));
		int arg26 = index + 1;
		r = sheet.createRow(arg26);
		c = r.createCell(0);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("类型"));
		c = r.createCell(1);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("日期"));
		c = r.createCell(2);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("主题"));
		c = r.createCell(3);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("内容"));
		c = r.createCell(4);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("创建人"));
		c = r.createCell(5);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("进度"));
		c = r.createCell(6);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("完成情况"));
		++arg26;
		List arg27 = (List) model.get("list");
		String calType = (String) model.get("type");
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm");

		for (int os = 0; os < arg27.size(); ++os) {
			Object[] objs = (Object[]) arg27.get(os);
			List listArr;
			if (calType != null && calType.equals("WEEK")) {
				listArr = (List) objs[2];
			} else {
				listArr = (List) objs[1];
			}

			if (listArr != null) {
				for (int j = 0; j < listArr.size(); ++j) {
					EstablishmentCommunicateBean bean = (EstablishmentCommunicateBean) listArr
							.get(j);
					EstablishmentCommunicate ec = bean.getCommunicate();
					String type = "";
					String comp = "";
					String compMark = "";
					if (ec.getCommType().equals("LOG")) {
						type = "工作日志";
						comp = "已完成";
					} else if (ec.getCommType().equals("PLAN")) {
						type = "工作计划";
						if (ec.getCompleted().equals("Y")) {
							comp = "已完成";
							compMark = ec.getCompleteMark();
						} else {
							comp = "进行中";
						}
					}

					r = sheet.createRow(arg26);
					c = r.createCell(0);
					c.setCellStyle(norStyle);
					c.setCellValue(new HSSFRichTextString(type));
					c = r.createCell(1);
					c.setCellStyle(norStyle);
					c.setCellValue(new HSSFRichTextString(sf.format(ec
							.getCommunicateTime())));
					c = r.createCell(2);
					c.setCellStyle(norStyle);
					c.setCellValue(new HSSFRichTextString(ec.getTitle()));
					c = r.createCell(3);
					c.setCellStyle(norStyle);
					c.setCellValue(new HSSFRichTextString(ec.getContent()));
					c = r.createCell(4);
					c.setCellStyle(norStyle);
					c.setCellValue(new HSSFRichTextString(ec.getCreaterName()));
					c = r.createCell(5);
					c.setCellStyle(norStyle);
					c.setCellValue(new HSSFRichTextString(comp));
					c = r.createCell(6);
					c.setCellStyle(norStyle);
					c.setCellValue(new HSSFRichTextString(compMark));
					++arg26;
				}
			}
		}

		sheet.setColumnWidth(1, 4000);
		sheet.setColumnWidth(2, 4000);
		sheet.setColumnWidth(3, 18000);
		ServletOutputStream arg28 = response.getOutputStream();
		workbook.write(arg28);
		arg28.flush();
		arg28.close();
	}
}